﻿$(function() {
    $.ajax({
        type: "GET",
        url: "../api/access.ashx",
        data: { type: 'getrole', roleid: roleid, r: Math.random() },
        dataType: "json",
        success: function(data) {
            $("#txt_rolename").val(data.rolename);
            $("#txt_description").val(data.description);
            formReady();
        }
    });
    $("form").validate({
        rules: { txt_rolename: "required", txt_description: "required" },
        submitHandler: function() {

            $("#btn_submit").attr("disabled", "disabled").after("<span>提交中.....</span>");

            $.ajax({
                type: "POST",
                url: "../api/access.ashx",
                data: { type: 'editrole', roleid: roleid, rolename: $('#txt_rolename').val(), desc: $("#txt_description").val() },
                dataType: "html",
                success: function(data) {
                    if (data == 1) {
                        facebox("修改身份成功！");
                    }
                    else {
                        facebox("修改身份失败！");
                    }

                    $("#btn_submit").attr("disabled", "").next("span").remove();
                }
            });
        }
    });
});